<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="12" :md="12" :sm="20">
            <a-form-item label="时间">
              <j-date placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <a-form-item label="资金类型">
              <j-dict-select-tag v-model="queryParam.type" dictCode="fund_type" placeholder="全部" clearable/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <a-form-item label="对方">
              <j-search-select-tag placeholder="请选择" v-model="queryParam.uid" dict="ums_member,nickname,id"
                                   :async="true"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <a-form-item label="关联单号">
              <j-input placeholder="请输入关联单号" v-model="queryParam.orderNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <a-form-item label="支付方式">
              <j-dict-select-tag v-model="queryParam.payChannel" dictCode="pay_cannel" placeholder="全部" clearable/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <a-form-item label="订单类型">
              <j-dict-select-tag v-model="queryParam.orderType" dictCode="fund_order_type" placeholder="全部" clearable/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('账单记录')"
                        style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table"
               size="middle"
               :scroll="{x:true}"
               bordered
               rowKey="id"
               :columns="columns"
               :dataSource="dataSource"
               :pagination="ipagination"
               :loading="loading"
               class="j-table-force-wrap"
               @change="handleTableChange">

        <template slot-scope="text" slot="orderTypeSlot">
          <a-tag color="green" v-if="text==1">
            充值订单
          </a-tag>
          <a-tag color="cyan" v-if="text==2">
            购买订单
          </a-tag>
          <a-tag color="blue" v-if="text==3">
            退款订单
          </a-tag>
          <a-tag color="purple" v-if="text==4">
            提现
          </a-tag>
        </template>

        <template slot="payChannelSlot" slot-scope="text,record">
          <span v-if="record.orderType == 4"></span>
          <span v-else>
          <a-tag color="#f50" v-if="text==0">
            余额-支付
          </a-tag>
          <a-tag color="#2db7f5" v-if="text==1">
            支付宝-支付
          </a-tag>
          <a-tag color="#87d068" v-if="text==2">
            微信-支付
          </a-tag>
          <a-tag color="#00AA00" v-if="text==3">
            公众号-支付
          </a-tag>
          <a-tag color="#66FF66" v-if="text==4">
            小程序-支付
          </a-tag>
          <a-tag color="#DDDDDD" v-if="text==5">
            Apple-支付
          </a-tag>
          <a-tag color="#FFB3FF" v-if="text==6">
            数字资产-支付
          </a-tag>
          </span>
        </template>

        <template slot="nicknameSlot" slot-scope="text, record">
          <span>{{
              record.type == 4 ? record.shopId_dictText : record.type == 6 ? record.supplierId_dictText : text
            }}</span>
        </template>
        <template slot="paySlot" slot-scope="text, record">
          <span>{{ record.orderType == 4 ? '' : text }}</span>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import JInput from '@/components/jeecg/JInput'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import {getAction} from "@api/manage"

export default {
  name: 'RmsFundLogList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    JInput,
    JSearchSelectTag
  },
  data() {
    return {
      description: '账单记录管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '资金类型',
          align: "center",
          dataIndex: 'type_dictText'
        },
        {
          title: '订单类型',
          align: "center",
          dataIndex: 'orderType',
          scopedSlots: {customRender: 'orderTypeSlot'}
        },
        {
          title: '昵称',
          align: "center",
          dataIndex: 'uid_dictText',
          scopedSlots: {customRender: "nicknameSlot"}
        },
        {
          title: '金额',
          align: "center",
          dataIndex: 'amount'
        },
        {
          title: '关联单号',
          align: "center",
          dataIndex: 'orderNo'
        },
        {
          title: '支付方式',
          align: "center",
          dataIndex: 'payChannel',
          scopedSlots: {customRender: "payChannelSlot"}
        },
        {
          title: '第三方流水号',
          align: "center",
          dataIndex: 'thirdOrderNo'
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime'
        },
      ],
      url: {
        list: "/rms/rmsFundLog/list",
        delete: "/rms/rmsFundLog/delete",
        deleteBatch: "/rms/rmsFundLog/deleteBatch",
        exportXlsUrl: "/rms/rmsFundLog/exportXls",
        importExcelUrl: "rms/rmsFundLog/importExcel",

      },
      choiceDate: undefined,
      dictOptions: {},
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      this.initCreateTime()
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件

      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
          this.onClearSelected()
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    initCreateTime() {
      if (this.choiceDate === undefined) {
        this.choiceDate = this.$route.query.date
      }
      if (this.$route.query.date !== undefined && this.choiceDate !== "") {
        this.queryParam.createTime_begin = this.choiceDate
        this.queryParam.createTime_end = this.choiceDate
        this.choiceDate = ""
      }
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
